import { ReqPage, ResPage } from "_common/DataType";
import { IotPoint } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

/**
 * 测点管理
 */
export class ApiPoint {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/iot/point";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 创建 */
  create(data: any) {
    return this.request.post<boolean>(this.url + "", data);
  }

  /** 更新 */
  update(data: any) {
    return this.request.put<boolean>(this.url + "", data);
  }

  /** 删除 */
  delete(id: number) {
    return this.request.delete<boolean>(this.url + "/" + id);
  }

  /** 获取设备列表 */
  getList(facilityId: number) {
    return this.request.get<IotPoint[]>(this.url + "/get-list/" + facilityId);
  }

  // 获取所有的点
  getAll() {
    return this.request.get<IotPoint[]>(this.url + "/get-all");
  }

  /**
   * 获取分页列表
   * @param params
   * @returns
   */
  getPage(params: ReqPage) {
    return this.request.get<ResPage<IotPoint>>(this.url + "/get-page", params);
  }

  /**
   * 批量删除
   * @param ids
   * @returns
   */
  batchDelete(ids: (string | number)[]) {
    return this.request.post<boolean>(this.url + "/batch-delete", ids);
  }

  // 导入文件
  import(facilityId: number, formData: FormData) {
    return this.request.post<boolean>(
      this.url + "/upload/" + facilityId,
      formData
    );
  }

  // 获取指定站点下的所有设备
  getDeviceByStation(stationId: number) {
    return this.request.get<any[]>(
      this.url + "/get-device-list/" + stationId,
      {}
    );
  }
}
